package kr.ac.kaist.ysproject;

import java.util.ArrayList;

import kr.ac.kaist.ysproject.data.DataMsgHistory;
import kr.ac.kaist.ysproject.data.DataSmartMsgInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class MsgHistoryAdapter extends ArrayAdapter<DataMsgHistory> {

	private Context mContext;
	private int mResource;
	private ArrayList<DataMsgHistory> mList;
	private LayoutInflater mInflater;

	public MsgHistoryAdapter(Context context, int layoutResource, ArrayList<DataMsgHistory> objects)
	{
		super(context, layoutResource, objects);
		this.mContext = context;
		this.mResource = layoutResource;
		this.mList = objects;
		this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}


	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		DataMsgHistory msgInfo = mList.get(position);

		if(convertView == null)
		{
			convertView = mInflater.inflate(mResource, null);
		}

		if(msgInfo != null)
		{
			TextView tvSentDate = (TextView) convertView.findViewById(R.id.tv_sentdate);
			TextView tvMsg = (TextView) convertView.findViewById(R.id.tv_msg);
			
			tvSentDate.setText("[" + msgInfo.getSentDate() + "]");
			tvMsg.setText(msgInfo.getMsg());

		}

		return convertView;
	}
}